import params from "@/api/prod.js";
import MD5 from "crypto-js/md5.js";

// // #ifndef H5
// export const isProduction = process.env.NODE_ENV === "production"
// // #endif

// #ifdef APP-PLUS
export const isProduction = true
// #endif


export const isLoginFailure = () => {
	const now = new Date().getTime();
	const hasToken = !!uni.getStorageSync('token')
	const loginTime = uni.getStorageSync('time') || 0
	const limTime = 1000 * 60 * 15;
	const result = now - loginTime >= limTime;
	return result || !hasToken;
};


export const get_uuid = () => {
	return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
		var r = (Math.random() * 16) | 0,
			v = c == "x" ? r : (r & 0x3) | 0x8;
		return v.toString(16);
	});
}

export const setParams = (data) => {
	// 获取当前10位的时间戳
	const timestamp = Math.round(new Date().getTime() / 1000).toString();
	// secret + 10位时间戳的前六位，然后进行两次MD5加密
	const sign = MD5(
		MD5(params.secret + timestamp.slice(0, 6)).toString()
	).toString();

	return {
		...data,
		timestamp: timestamp,
		from: params.from,
		sign: sign,
		companyId: params.companyId,
	}
}
